﻿// CGotoDlg.cpp: 实现文件
//

#include "pch.h"
#include "CClient.h"
#include "CGotoDlg.h"
#include "afxdialogex.h"


// CGotoDlg 对话框

IMPLEMENT_DYNAMIC(CGotoDlg, CDialogEx)

CGotoDlg::CGotoDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_GOTO, pParent)
{

}

CGotoDlg::~CGotoDlg()
{
}

void CGotoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_CLEAR, m_clear);
}


BEGIN_MESSAGE_MAP(CGotoDlg, CDialogEx)
	ON_EN_CHANGE(IDC_EDIT_LINE, &CGotoDlg::OnChangeEditLine)
END_MESSAGE_MAP()


// CGotoDlg 消息处理程序


BOOL CGotoDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	SetDlgItemInt(IDC_EDIT_LINE, m_nLine);
	CString str;
	str.Format(_T("行号(1-%d)(&L)"), m_nLines);
	SetDlgItemText(IDC_LINE, str);

	// 将清空图标的父View设置为编辑框
	CWnd* pEdit = GetDlgItem(IDC_EDIT_LINE);
	m_clear.SetParent(pEdit);
	CRect rect;
	// 获取编辑框自身的矩阵
	pEdit->GetClientRect(rect);
	// 让清空图标移动位置
	rect.left = rect.right - rect.Height();
	m_clear.MoveWindow(rect, FALSE);

	// rect x 左右缩小的值， y 上下缩小的值
	// rect.DeflateRect(x, y);

	// RichEdit 收不到变换消息
	CRichEditCtrl* rd = (CRichEditCtrl*) GetDlgItem(IDC_EDIT_LINE);
	rd->SetEventMask(rd->GetEventMask() | ENM_CHANGE);

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}

// Edit控件监听
void CGotoDlg::OnChangeEditLine()
{
	// TODO:  如果该控件是 RICHEDIT 控件，它将不
	// 发送此通知，除非重写 CDialogEx::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask()，
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
	int n = GetDlgItemInt(IDC_EDIT_LINE);
	m_clear.ShowWindow(n > 0 ? SW_SHOW : SW_HIDE);
	GetDlgItem(IDOK)->EnableWindow(n > 0);
}


void CGotoDlg::OnOK()
{
	m_nLine = GetDlgItemInt(IDC_EDIT_LINE);
	EndDialog(IDOK);
}
